<?phpdate_default_timezone_set("Asia/Bangkok");require_once( 'class_db_loader.php');define('DS', DIRECTORY_SEPARATOR);define('ROOT_PATH',dirname( dirname(__FILE__)));class core {    var $db;    var $rand_key;    static $count_select = 0;    #============================================================    # Construct    #============================================================    function __construct() {        if(!isset($_SESSION))        {            session_start();        }        $dbConnection = new db();        $this->db = $dbConnection->connect('', '', 'recruitment_test', '');        $this->rand_key = 'JBMdaTkGbe3qyE2';        self::$count_select = 0;//        $seconds_to_cache = 3600;//        $ts = gmdate("D, d M Y H:i:s", time() + $seconds_to_cache) . " GMT";//        header("Expires: $ts");//        header("Pragma: cache");//        header("Cache-Control: max-age=$seconds_to_cache");        //set error handler    }    function GetAbsoluteURLFolder() {        $scriptFolder = (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on')) ? 'https://' : 'http://';        $scriptFolder .= $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']);        return $scriptFolder;    }    function getAllBrand() {        $array_brand_name = array();        $array_brand_id = array();        if ($this->db) {            $query = "SELECT manufacture_id,manufacture_name FROM zen_manufacture";            $brands = $this->db->get_results($query);            foreach ($brands as $brand) {                $array_brand_name[] = strtolower($brand->manufacture_name);                $array_brand_id[] = $brand->manufacture_id;            }        }        $array_brand = array();        $array_brand["id"] = $array_brand_id;        $array_brand["name"] = $array_brand_name;        return $array_brand;    }    function checkExistProduct($code) {        if ($this->db) {            $query = "SELECT * FROM zen_product WHERE product_code = '" . $code . "'";            $product = $this->db->get_row($query);            if ($product) {                return true;            } else {                return false;            }        }    }    function checkZenOrderByID($zen_order_id) {        if ($this->db) {            $query = "SELECT * FROM zen_order WHERE zen_order_id =$zen_order_id";            $zen_order = $this->db->get_row($query);            if ($zen_order) {                return $zen_order;            } else {                return false;            }        }    }    function checkZenCustomerOrderDetail($item_id) {        if ($this->db) {            $query = "SELECT * FROM zen_customer_order_detail WHERE id =$item_id";            $zen_order = $this->db->get_row($query);            if ($zen_order) {                return $zen_order;            } else {                return false;            }        }    }    function getZenCustomerOrderDetailById($zen_customer_order_detail_id) {        if ($this->db) {            $query = "SELECT * FROM zen_customer_order_detail WHERE id =$zen_customer_order_detail_id";            $zen_order_detail = $this->db->get_row($query);            if ($zen_order_detail) {                return $zen_order_detail;            } else {                return false;            }        }    }    function getZenCustomerOrderById($customer_order_id) {        if ($this->db) {            $query = "SELECT * FROM zen_customer_order WHERE customer_order_id =$customer_order_id";            $zen_customer_order = $this->db->get_row($query);            if ($zen_customer_order) {                return $zen_customer_order;            } else {                return false;            }        }    }    function checkExistCustomer($phone) {        if ($this->db) {            $query = "SELECT * FROM zen_customer WHERE phone = '" . $phone . "'";            $customer = $this->db->get_row($query);            if ($customer) {                return true;            } else {                return false;            }        }    }    function getCrawlCategoryByParentId($parent_id) {        global $core;        if ($core->db) {            $query = "SELECT * FROM zen_crawl_category WHERE parent_id =$parent_id";            $category = $core->db->get_results($query);            return $category;        } else {            return false;        }    }    function getCrawlTotalChildCategoryById($category_id) {        global $core;        if ($core->db) {            $query = "SELECT count(id) as total FROM zen_crawl_category WHERE parent_id =$category_id";            $category = $core->db->get_row($query);            return $category->total;        } else {            return false;        }    }    function getListCrawlCategoryByParentId($category_id){        $array_category = array();        if($category_id > 0){            $array_category[]=$category_id;        }        $list_category = $this->getCrawlCategoryByParentId($category_id);        if($list_category){            foreach($list_category as $category){                $array_category[]=$category->id;                $total_child_category = $this->getCrawlTotalChildCategoryById($category->id);                if($total_child_category>0){                    $tmp = $this->getListCrawlCategoryByParentId($category->id);                    $array_category = array_merge($array_category,$tmp);                }            }        }        return $array_category;    }    function getCrawlProductListByCategory($category_id,$page = 1, &$load_more = 0,&$total_product, $item_per_page = 25) {        if ($page >= 1) {            $from = ($page - 1) * $item_per_page;        } else {            $from = 0;        }        if ($this->db) {            if($category_id>0){                $list_category = $this->getListCrawlCategoryByParentId($category_id);                $string_category_id= implode(",",$list_category);                $query = "SELECT *                      FROM zen_crawl_product zcp                      WHERE zcp.id IN (SELECT DISTINCT product_id                                       FROM zen_crawl_category_product zccp                                       WHERE zccp.category_id IN ($string_category_id)                                       )                      LIMIT $from,$item_per_page";                $query_total = "SELECT count(DISTINCT product_id) as total                                       FROM zen_crawl_category_product zccp                                       WHERE zccp.category_id IN ($string_category_id)";            }else{                $query = "SELECT *                      FROM zen_crawl_product zcp                      LIMIT $from,$item_per_page";                $query_total = "SELECT count(id) as total                      FROM zen_crawl_product                      ";            }            $product = $this->db->get_results($query);            $total = $this->db->get_row($query_total);            if ($total) {                $total_product = $total->total;                if ($total->total > $page * $item_per_page) {                    $load_more = 1;                } else {                    $load_more = 0;                }            } else {                $load_more = 0;            }            return $product;        }    }    function getListCrawlCategoryByLevel($level){        if ($this->db) {            $query = "SELECT *                      FROM zen_crawl_category WHERE level=$level                    ";            $category_list = $this->db->get_results($query);            return $category_list;        }    }    function getCompareProductList($page = 1, &$load_more = 0,&$total_product, $item_per_page = 25){        if ($page >= 1) {            $from = ($page - 1) * $item_per_page;        } else {            $from = 0;        }        if ($this->db) {            $query = "SELECT zcp.product_name,                        zp.product_code,zp.main_photo as old_photo,zcp.main_photo as new_photo                      FROM zen_crawl_product zcp, zen_product zp                      WHERE zcp.`product_code` = zp.`product_code`                      ORDER BY zp.product_id DESC                      LIMIT $from,$item_per_page";            $product = $this->db->get_results($query);            $query_total = "SELECT count(zp.product_id) as total                      FROM zen_crawl_product zcp, zen_product zp                      WHERE zcp.`product_code` = zp.`product_code`                      ";            $total = $this->db->get_row($query_total);            if ($total) {                $total_product = $total->total;                if ($total->total > $page * $item_per_page) {                    $load_more = 1;                } else {                    $load_more = 0;                }            } else {                $load_more = 0;            }            return $product;        }    }    function getListProduct($page = 1, &$load_more = 0, $item_per_page = 25) {        if ($page >= 1) {            $from = ($page - 1) * $item_per_page;        } else {            $from = 0;        }        if ($this->db) {            $query = "SELECT product_id,manufacture,product_name,                        product_code,main_photo,description,product_price                                              FROM zen_product zp                      ORDER BY product_id DESC                      LIMIT $from,$item_per_page";            $product = $this->db->get_results($query);            $query_total = "SELECT count(product_id) as total                      FROM zen_product                      ";            $total = $this->db->get_row($query_total);            if ($total) {                if ($total->total > $page * $item_per_page) {                    $load_more = 1;                } else {                    $load_more = 0;                }            } else {                $load_more = 0;            }            return $product;        }    }    function searchProduct($text_search, $page = 1, &$load_more = 0, $item_per_page = 25) {        if ($page >= 1) {            $from = ($page - 1) * $item_per_page;        } else {            $from = 0;        }        if ($this->db) {            $query = "SELECT DISTINCT(product_id),manufacture,product_name,                        product_code,main_photo,description,product_price                                              FROM zen_product zp                      WHERE product_name LIKE '%$text_search%' OR product_code LIKE '%$text_search%'                      ORDER BY product_id DESC                      LIMIT $from,$item_per_page";            $product = $this->db->get_results($query);            $query_total = "SELECT count(DISTINCT(product_id)) as total                      FROM zen_product                      WHERE product_name LIKE '%$text_search%' OR product_code LIKE '%$text_search%'                      ";            $total = $this->db->get_row($query_total);            if ($total) {                if ($total->total > $page * $item_per_page) {                    $load_more = 1;                } else {                    $load_more = 0;                }            } else {                $load_more = 0;            }            return $product;        }    }    function searchCustomer($text_search, $page = 1, &$load_more = 0, $item_per_page = 25) {        if ($page >= 1) {            $from = ($page - 1) * $item_per_page;        } else {            $from = 0;        }        if ($this->db) {            $query = "SELECT DISTINCT(customer_id),name,facebook_name,                        facebook_link,phone,VIP                      FROM zen_customer zc                      WHERE name LIKE '%$text_search%' OR facebook_name LIKE '%$text_search%' OR phone LIKE '%$text_search%'                      ORDER BY customer_id DESC                      LIMIT $from,$item_per_page";            $customer = $this->db->get_results($query);            $query_total = "SELECT count(DISTINCT(customer_id)) as total                      FROM zen_customer                      WHERE name LIKE '%$text_search%' OR facebook_name LIKE '%$text_search%' OR phone LIKE '%$text_search%'                      ";            $total = $this->db->get_row($query_total);            if ($total) {                if ($total->total > $page * $item_per_page) {                    $load_more = 1;                } else {                    $load_more = 0;                }            } else {                $load_more = 0;            }            return $customer;        }    }    function getListOrder($page = 1, &$load_more = 0, $item_per_page = 25) {        if ($page >= 1) {            $from = ($page - 1) * $item_per_page;        } else {            $from = 0;        }        if ($this->db) {            $query = "SELECT *                      FROM zen_order                      ORDER BY create_time desc                      LIMIT $from,$item_per_page";            $order = $this->db->get_results($query);            $query_total = "SELECT count(zen_order_id) as total                      FROM zen_order                      ";            $total = $this->db->get_row($query_total);            if ($total) {                if ($total->total > $page * $item_per_page) {                    $load_more = 1;                } else {                    $load_more = 0;                }            } else {                $load_more = 0;            }            return $order;        }    }//    function getListCustomerOrder($zen_order_id, $page = 1, &$load_more = 0, &$total_result = array(), $item_per_page = 25) {//        if ($page > 1) {//            $from = ($page - 1) * $item_per_page;//        } else {//            $from = 0;//        }//        if ($this->db) {//            $query = "SELECT  temp.total_product,temp.total_at,temp.total_pt,temp.id,zco.total_order_money,zco.total_payment,//                            zco.total_current_money,zco.customer_order_status,temp.customer_order_id,//                            zc.customer_id,facebook_name,facebook_link,address,name,bank_account,province,phone,//                            temp.main_photo,temp.link_web,temp.product_code,temp.product_size,//                            temp.product_color,temp.product_num,temp.product_price,//                            temp.order_status,temp.product_available,zco.order_description,temp.description//                        FROM ( SELECT total_product,total_at,total_pt,zcod.id,zcod.customer_order_id,link_web,main_photo,//                        product_code,zcod.product_size,zcod.product_color,product_num,zcod.product_price,//                        order_status,product_available,zcod.description//                                FROM zen_product zp, zen_customer_order_detail zcod,//                                    ( SELECT COUNT(zcod.customer_order_id) AS total_product,SUM(zcod.product_num*zp.stamp_price) AS total_at,//                                    zcod.customer_order_id,SUM(zcod.product_num*zp.store_price) AS total_pt//                                    FROM zen_customer_order_detail zcod, zen_customer_order zco, zen_order zo,zen_product zp//                                    WHERE  zcod.customer_order_id = zco.customer_order_id //                                    AND    zp.product_id = zcod.product_id //                                    AND    zco.zen_order_id = zo.zen_order_id AND zo.zen_order_id =$zen_order_id//                                   //                                    GROUP BY zcod.customer_order_id) temp_2//                                WHERE zp.product_id = zcod.product_id //                                        AND temp_2.customer_order_id= zcod.customer_order_id//                                 ORDER BY zcod.customer_order_id DESC) temp,//                                //                                zen_customer zc, zen_customer_order zco, zen_order zo//                        WHERE (temp.customer_order_id = zco.customer_order_id AND //                        zco.zen_order_id = zo.zen_order_id//                        AND zc.customer_id = zco.customer_id AND zo.zen_order_id = $zen_order_id)//                       ORDER BY customer_order_id DESC//                      LIMIT $from,$item_per_page";////            $customer_order = $this->db->get_results($query);//            $query_total = "SELECT count(id) as total,SUM(product_num) AS total_product//                       FROM zen_customer_order_detail zcod,zen_customer_order zco//                       WHERE zcod.customer_order_id= zco.customer_order_id AND zco.zen_order_id= $zen_order_id//                      ";//            $total = $this->db->get_row($query_total);////            $total_result["total_product"] = 0;//            if ($total) {//                $total_result["total_product"] = $total->total_product;//                if ($total->total > $page * $item_per_page) {//                    $load_more = 1;//                } else {//                    $load_more = 0;//                }//            } else {//                $load_more = 0;//            }////            $result = $this->db->get_results("SELECT COUNT(zco.customer_order_id) AS total_customer, SUM(total_order_money) AS total_order_money,//                                                            SUM(total_payment) AS total_payment, SUM(total_current_money) AS total_current_money,//                                                            SUM(temp.total_at) AS total_at, SUM(temp.total_pt) AS total_pt//                                             FROM zen_customer_order zco ,( SELECT SUM(zcod.product_num*zp.stamp_price) AS total_at,//                                                                                    zcod.customer_order_id,SUM(zcod.product_num*zp.store_price) AS total_pt//                                                                            FROM zen_customer_order_detail zcod, zen_customer_order zco, zen_order zo,zen_product zp//                                                                            WHERE  zcod.customer_order_id = zco.customer_order_id //                                                                                    AND    zp.product_id = zcod.product_id //                                                                                    AND    zco.zen_order_id = zo.zen_order_id AND zo.zen_order_id =$zen_order_id//                                   //                                                                            GROUP BY zcod.customer_order_id) temp//                                            WHERE  zco.customer_order_id=temp.customer_order_id AND  total_current_money >=0 AND zco.zen_order_id=$zen_order_id//                                        UNION //                                        SELECT COUNT(zco.customer_order_id) AS total_customer, SUM(total_order_money) AS total_order_money,//                                                            SUM(total_payment) AS total_payment, SUM(total_current_money) AS total_current_money,//                                                            SUM(temp.total_at) AS total_at, SUM(temp.total_pt) AS total_pt//                                             FROM zen_customer_order zco ,( SELECT SUM(zcod.product_num*zp.stamp_price) AS total_at,//                                                                                    zcod.customer_order_id,SUM(zcod.product_num*zp.store_price) AS total_pt//                                                                            FROM zen_customer_order_detail zcod, zen_customer_order zco, zen_order zo,zen_product zp//                                                                            WHERE  zcod.customer_order_id = zco.customer_order_id //                                                                                    AND    zp.product_id = zcod.product_id //                                                                                    AND    zco.zen_order_id = zo.zen_order_id AND zo.zen_order_id =$zen_order_id//                                   //                                                                            GROUP BY zcod.customer_order_id) temp//                                            WHERE  zco.customer_order_id=temp.customer_order_id AND  total_current_money <0 AND zco.zen_order_id=$zen_order_id ");//            $total_result["total_customer"] = 0;//            $total_result["total_order_money"] = 0;//            $total_result["total_payment"] = 0;//            $total_result["total_excess_cash"] = 0;//            $total_result["total_debit"] = 0;//            $total_result["total_at"] = 0;//            $total_result["total_pt"] = 0;//            if ($result) {////                $total_result["total_customer"] = 0;//                $total_result["total_order_money"] = 0;//                $total_result["total_payment"] = 0;//                $total_result["total_excess_cash"] = 0;//                $total_result["total_debit"] = 0;//                $i = 1;//                foreach ($result as $data) {//                    if ($data->total_customer > 0) {//                        if ($i == 1) {//                            $total_result["total_customer"] = $data->total_customer;//                            $total_result["total_order_money"] = $data->total_order_money;//                            $total_result["total_payment"] = $data->total_payment;//                            $total_result["total_excess_cash"] = $data->total_current_money;//                            $total_result["total_at"] = $data->total_at;//                            $total_result["total_pt"] = $data->total_pt;//                            $i++;//                        } else {//                            $total_result["total_customer"] = $total_result["total_customer"] + $data->total_customer;//                            $total_result["total_order_money"] = $total_result["total_order_money"] + $data->total_order_money;//                            $total_result["total_payment"] = $total_result["total_payment"] + $data->total_payment;//                            $total_result["total_debit"] = $data->total_current_money;//                            $total_result["total_at"] = $total_result["total_at"] + $data->total_at;//                            $total_result["total_pt"] = $total_result["total_pt"] + $data->total_pt;//                        }//                    }//                }//            }//            return $customer_order;//        }//    }    function getCustomerOrderDetailById($customer_order_id) {        if ($this->db) {            $query = "SELECT  zco.customer_id, zco.code_view,zco.type_calculate_payment,zco.service_percent,                              zco.fee_per_kg,zco.weight,zco.exchange,temp.id,temp.customer_order_id,                            zc.customer_id,facebook_name,name, email,wholesale,facebook_link,address,province,phone,temp.description,                            temp.id, temp.product_id, temp.main_photo,temp.product_code,temp.product_size,                            temp.product_color,temp.product_num,temp.order_product_num,temp.product_price,                            temp.order_status,temp.product_available,zco.order_description,                            temp.customer_order_date,temp.online_date,temp.store_date,                            temp.saled_date,temp.received_date,temp.store_price,temp.stamp_price,temp.manufacture                        FROM ( SELECT zcod.id,zcod.customer_order_id,zp.product_id,main_photo,product_code,                        zcod.product_size,zcod.product_color,product_num,order_product_num,zcod.product_price,                        order_status,product_available,zcod.description,zcod.customer_order_date,                        zcod.online_date,zcod.store_date,zcod.saled_date,zcod.received_date                        ,zcod.store_price,zcod.stamp_price,zp.manufacture                                FROM zen_product zp, zen_customer_order_detail zcod                                                                   WHERE zp.product_id = zcod.product_id                                        AND zcod.customer_order_id=$customer_order_id                                  ORDER BY zcod.id DESC) temp,                                                                zen_customer zc, zen_customer_order zco                        WHERE (temp.customer_order_id = zco.customer_order_id                        AND zc.customer_id = zco.customer_id )                      ";            $customer_order = $this->db->get_results($query);            return $customer_order;        }    }    function getListCustomerOrderFilterByCustomer($zen_order_id, $order_by, $where, $page = 1, &$load_more = 0, &$total_result = array(), $item_per_page = 25) {        if ($page > 1) {            $from = ($page - 1) * $item_per_page;        } else {            $from = 0;        }        if ($this->db) {            $where_total = '';            if ($where != "") {                $where_total.=" AND " . $where;            }            $query = "SELECT  temp.total_product,temp.total_money,temp.total_at,temp.total_pt,temp.id,                            zco.total_order_money,zco.total_payment,zco.total_current_money,zco.customer_order_status,                            zco.type_calculate_payment,zco.service_percent,zco.fee_per_kg, zco.weight,                            temp.customer_order_id,                            zc.customer_id,facebook_name,facebook_link,address,province,phone,name,bank_account,                            temp.main_photo,temp.link_web,temp.product_code,temp.product_size,                            temp.product_color,temp.product_num,temp.order_product_num,temp.product_price,                            temp.order_status,temp.product_available,temp.customer_order_date,                            temp.online_date,temp.store_date,temp.saled_date,temp.received_date,zco.code_view,                            zco.order_description,temp.description,temp.store_price,temp.stamp_price,temp.manufacture                        FROM ( SELECT total_product,total_money,total_at,total_pt,zcod.id,zcod.customer_order_id,link_web,main_photo,product_code,                                        zcod.product_size,zcod.product_color,product_num,order_product_num,zcod.product_price,                                        order_status,product_available,zcod.customer_order_date,zcod.online_date,                                        zcod.store_date,zcod.saled_date,zcod.received_date,zcod.description,                                        zcod.product_id,zcod.store_price,zcod.stamp_price,zp.manufacture,zp.`product_category`                                FROM zen_product zp, zen_customer_order_detail zcod,                                    (                                      SELECT DISTINCT customer_order_id,total_money,total_at,total_pt FROM                                            (                                                SELECT SUM(zcod.product_num*zcod.product_price) AS total_money,                                                        zcod.customer_order_id, SUM(zcod.product_num*zcod.stamp_price) AS total_at,                                                        SUM(zcod.product_num*zcod.store_price) AS total_pt                                                FROM zen_customer_order_detail zcod, zen_customer_order zco, zen_order zo,zen_product zp,zen_customer zc                                                WHERE  zcod.customer_order_id = zco.customer_order_id AND                                                        zp.product_id = zcod.product_id AND zc.customer_id = zco.customer_id AND                                                         zcod.order_status != 6 AND                                                        zco.zen_order_id = zo.zen_order_id AND zo.zen_order_id =$zen_order_id" . $where_total . "                                                GROUP BY zcod.customer_order_id                                            UNION                                                SELECT 0,zcod.customer_order_id,0,0                                                FROM zen_customer_order_detail zcod, zen_customer_order zco, zen_order zo,zen_product zp,zen_customer zc                                                WHERE  zcod.customer_order_id = zco.customer_order_id AND                                                        zp.product_id = zcod.product_id AND zc.customer_id = zco.customer_id AND                                                        zcod.order_status = 6 AND                                                        zco.zen_order_id = zo.zen_order_id AND zo.zen_order_id =$zen_order_id" . $where_total . "                                                GROUP BY zcod.customer_order_id                                             ) temp_4                                        GROUP BY customer_order_id                                    ) temp_2,                                    (                                        SELECT COUNT(zcod.customer_order_id) AS total_product,zcod.customer_order_id                                        FROM zen_customer_order_detail zcod, zen_customer_order zco, zen_order zo,zen_product zp,zen_customer zc                                        WHERE  zcod.customer_order_id = zco.customer_order_id AND                                                zp.product_id = zcod.product_id AND zc.customer_id = zco.customer_id AND                                                zco.zen_order_id = zo.zen_order_id AND zo.zen_order_id =$zen_order_id" . $where_total . "                                        GROUP BY zcod.customer_order_id                                    ) temp_3                                WHERE zp.product_id = zcod.product_id                                         AND temp_2.customer_order_id= zcod.customer_order_id                                        AND temp_3.customer_order_id = zcod.customer_order_id                                 ORDER BY zcod.customer_order_id DESC) temp,                                                                zen_customer zc, zen_customer_order zco, zen_order zo                        WHERE temp.customer_order_id = zco.customer_order_id AND                         zco.zen_order_id = zo.zen_order_id                         AND zc.customer_id = zco.customer_id AND zo.zen_order_id = $zen_order_id";            if ($where != "") {                $query.=" AND " . $where;            }            if ($order_by != "") {                $query.=" ORDER BY " . $order_by;            }            if ($item_per_page > 0) {                $query.=" LIMIT $from,$item_per_page";            }            $file = 'debug_crawl.txt';            file_put_contents($file, $query);            $customer_order = $this->db->get_results($query);            $query_total = "SELECT count(id) as total,SUM(product_num) AS total_product                       FROM zen_customer_order_detail zcod,zen_customer_order zco,zen_customer zc,zen_product zp                       WHERE zcod.customer_order_id= zco.customer_order_id                         AND zp.product_id = zcod.product_id                       AND zc.customer_id = zco.customer_id AND zco.zen_order_id= $zen_order_id                      ";            if ($where != "") {                $query_total.=" AND " . $where;            }            $total = $this->db->get_row($query_total);            $total_result["total_product_order"] = 0;            if ($total) {                $total_result["total_product_order"] = $total->total_product;                if ($total->total > $page * $item_per_page) {                    $load_more = 1;                } else {                    $load_more = 0;                }            } else {                $load_more = 0;            }            $sql_where = '';            if ($where != "") {                $sql_where.=" AND " . $where;            }            //tính tổng này còn phải theo điều kiện đầu vào nên tổng AT,PT vẫn phải tính dựa vào từng sản phẩm trong đơn hàng            //còn tổng tiền do tính theo 3 cách khách nhau normal, AT,PT nên phải lấy ở bảng zen_customer_order            //tổng tiền chỉ hiển thi khi tìm kiếm gom nhóm theo khách hàng, còn gom theo mã sp thì ko hiển thị vì nó không đúng            //do gom nhóm theo sản phẩm thì ko có được cân nặng để tính theo công thức            $query_result = "(SELECT COUNT(zco.customer_order_id) AS total_customer,                                    SUM(temp.total_order_money) AS total_order_money,                                    SUM(temp.total_product) AS total_product_real,                                    SUM(total_payment) AS total_payment,                                     SUM(total_current_money) AS total_current_money,                                    SUM(total_at) as total_at,                                    SUM(total_pt) as total_pt                            FROM zen_customer_order zco,                                (                                    SELECT zco.customer_order_id,                                            zco.total_order_money,                                            SUM(zcod.product_num) AS total_product,                                            SUM(zcod.product_num*zcod.stamp_price) AS total_at,                                            SUM(zcod.product_num*zcod.store_price) AS total_pt                                    FROM zen_customer_order_detail zcod,zen_customer_order zco ,zen_customer zc,zen_product zp                                    WHERE  zco.customer_order_id=zcod.customer_order_id                                            AND zp.product_id= zcod.product_id                                            AND zco.customer_id=zc.customer_id                                            AND zcod.order_status != 6                                            AND  zco.zen_order_id=$zen_order_id" . $sql_where . "                                    GROUP BY zco.customer_order_id                                ) temp                            WHERE  total_current_money >=0                                 AND zco.customer_order_id =temp.customer_order_id)                    UNION                            (SELECT COUNT(zco.customer_order_id) AS total_customer,                                    SUM(temp.total_order_money) AS total_order_money,                                    SUM(temp.total_product) AS total_product_real,                                    SUM(total_payment) AS total_payment,                                    SUM(total_current_money) AS total_current_money,                                    SUM(total_at) as total_at,                                    SUM(total_pt) as total_pt                            FROM zen_customer_order zco,                                (                                    SELECT zco.customer_order_id,                                            zco.total_order_money,                                            SUM(zcod.product_num) AS total_product,                                            SUM(zcod.product_num*zcod.stamp_price) AS total_at,                                            SUM(zcod.product_num*zcod.store_price) AS total_pt                                    FROM zen_customer_order_detail zcod,zen_customer_order zco ,zen_customer zc,zen_product zp                                    WHERE  zco.customer_order_id=zcod.customer_order_id                                            AND zp.product_id= zcod.product_id                                            AND zco.customer_id=zc.customer_id                                            AND zcod.order_status != 6                                            AND  zco.zen_order_id=$zen_order_id" . $sql_where . "                                     GROUP BY zco.customer_order_id                                ) temp                            WHERE  total_current_money <0                                    AND zco.customer_order_id =temp.customer_order_id)";            $result = $this->db->get_results($query_result);            $total_result["total_product"] = 0;//tong so san pham thuc su mua duoc            $total_result["total_customer"] = 0;            $total_result["total_order_money"] = 0;            $total_result["total_payment"] = 0;            $total_result["total_excess_cash"] = 0;            $total_result["total_debit"] = 0;            $total_result["total_at"] = 0;            $total_result["total_pt"] = 0;            if ($result) {                $i = 1;                foreach ($result as $data) {                    if ($i == 1) {                        $total_result["total_customer"] = $data->total_customer;                        $total_result["total_product"] = $data->total_product_real;                        $total_result["total_order_money"] = $data->total_order_money;                        $total_result["total_payment"] = $data->total_payment;                        $total_result["total_excess_cash"] = $data->total_current_money;                        $total_result["total_at"] = $data->total_at;                        $total_result["total_pt"] = $data->total_pt;                        $i++;                    } else {                        $total_result["total_customer"] = $total_result["total_customer"] + $data->total_customer;                        $total_result["total_product"] = $total_result["total_product"] + $data->total_product_real;                        $total_result["total_order_money"] = $total_result["total_order_money"] + $data->total_order_money;                        $total_result["total_payment"] = $total_result["total_payment"] + $data->total_payment;                        $total_result["total_debit"] = $data->total_current_money;                        $total_result["total_at"] = $total_result["total_at"] + $data->total_at;                        $total_result["total_pt"] = $total_result["total_pt"] + $data->total_pt;                    }                }            }            return $customer_order;        }    }    function getInfoByOrderStatus($zen_order_id, $customer_order_id, $where, &$total_result, $is_single) {        if ($this->db) {            $query = "SELECT  temp.total_product,temp.total_money,temp.total_at,temp.total_pt,temp.id,                            zco.total_order_money,zco.total_payment,zco.total_current_money,zco.customer_order_status,                            zco.type_calculate_payment,zco.service_percent, zco.fee_per_kg, zco.weight,                            temp.customer_order_id,                            zc.customer_id,facebook_name,facebook_link,address,province,phone,name,bank_account,                            temp.main_photo,temp.link_web,temp.product_code,temp.product_size,                            temp.product_color,temp.product_num,temp.order_product_num,temp.product_price,                            temp.order_status,temp.product_available,temp.customer_order_date,                            temp.online_date,temp.store_date,temp.saled_date,temp.received_date,zco.code_view,                            zco.order_description,temp.description,temp.store_price,temp.stamp_price,temp.manufacture                        FROM ( SELECT total_product,total_money,total_at,total_pt,zcod.id,zcod.customer_order_id,link_web,main_photo,product_code,                                        zcod.product_size,zcod.product_color,product_num,order_product_num,zcod.product_price,                                        order_status,product_available,zcod.customer_order_date,zcod.online_date,                                        zcod.store_date,zcod.saled_date,zcod.received_date,zcod.description,                                        zcod.product_id,zcod.store_price,zcod.stamp_price,zp.manufacture                                FROM zen_product zp, zen_customer_order_detail zcod,                                    (                                        SELECT DISTINCT customer_order_id,total_money,total_at,total_pt FROM                                            (                                                    SELECT SUM(zcod.product_num*zcod.product_price) AS total_money,                                                            zcod.customer_order_id, SUM(zcod.product_num*zcod.stamp_price) AS total_at,                                                            SUM(zcod.product_num*zcod.store_price) AS total_pt                                                    FROM zen_customer_order_detail zcod, zen_customer_order zco                                                    WHERE  zcod.customer_order_id = zco.customer_order_id AND                                                            zcod.order_status != 6 AND                                                            zcod.customer_order_id = $customer_order_id                                                    GROUP BY zcod.customer_order_id                                                UNION                                                    SELECT 0,$customer_order_id,0,0                                                    FROM zen_customer_order_detail zcod, zen_customer_order zco                                                    WHERE  zcod.customer_order_id = zco.customer_order_id AND                                                            zcod.order_status = 6 AND                                                            zcod.customer_order_id = $customer_order_id                                                    GROUP BY zcod.customer_order_id                                            ) temp_4                                    ) temp_2,                                    (                                        SELECT COUNT(zcod.customer_order_id) AS total_product,zcod.customer_order_id                                        FROM zen_customer_order_detail zcod, zen_customer_order zco                                        WHERE  zcod.customer_order_id = zco.customer_order_id AND                                                zcod.customer_order_id = $customer_order_id                                        GROUP BY zcod.customer_order_id                                    ) temp_3                                WHERE zp.product_id = zcod.product_id                                         AND temp_2.customer_order_id= zcod.customer_order_id                                        AND temp_3.customer_order_id= zcod.customer_order_id                                 ORDER BY zcod.customer_order_id DESC) temp,                                                                zen_customer zc, zen_customer_order zco                        WHERE temp.customer_order_id = zco.customer_order_id AND                                 zc.customer_id = zco.customer_id";            if ($is_single == 1) {                //chỉ lấy row đầu tiên: chỉ quan tâm đến total                $customer_order = $this->db->get_row($query);            } else {                //lấy tất cả thong tin cua order                $customer_order = $this->db->get_results($query);            }            $query_total = "SELECT SUM(product_num) AS total_product                       FROM zen_customer_order_detail zcod,zen_customer_order zco,zen_customer zc,zen_product zp                       WHERE zcod.customer_order_id= zco.customer_order_id                         AND zp.product_id = zcod.product_id                       AND zc.customer_id = zco.customer_id AND zco.zen_order_id= $zen_order_id                      ";            if ($where != "") {                $query_total.=" AND " . $where;            }            $total = $this->db->get_row($query_total);            $total_result["total_product"] = 0;            if ($total) {                $total_result["total_product"] = $total->total_product;            }            $sql_where = '';            if ($where != "") {                $sql_where.=" AND " . $where;            }            $query_result = "(SELECT COUNT(zco.customer_order_id) AS total_customer,                                    SUM(temp.total_order_money) AS total_order_money,                                    SUM(temp.total_product) AS total_product_real,                                    SUM(total_payment) AS total_payment,                                    SUM(total_current_money) AS total_current_money,                                    SUM(total_at) as total_at,                                     SUM(total_pt) as total_pt                             FROM zen_customer_order zco,                                    (                                        SELECT zco.customer_order_id,                                                zco.total_order_money,                                                SUM(zcod.product_num) AS total_product,                                                SUM(zcod.product_num*zcod.stamp_price) AS total_at,                                                SUM(zcod.product_num*zcod.store_price) AS total_pt                                        FROM zen_customer_order_detail zcod,zen_customer_order zco ,zen_customer zc,zen_product zp                                        WHERE  zco.customer_order_id=zcod.customer_order_id AND zp.product_id= zcod.product_id                                                AND zco.customer_id=zc.customer_id                                                AND zcod.order_status != 6                                                AND  zco.zen_order_id=$zen_order_id" . $sql_where . "                                        GROUP BY zco.customer_order_id                                    ) temp                             WHERE  total_current_money >=0                                    AND zco.customer_order_id =temp.customer_order_id)                     UNION                             (SELECT COUNT(zco.customer_order_id) AS total_customer,                                        SUM(temp.total_order_money) AS total_order_money,                                        SUM(temp.total_product) AS total_product_real,                                        SUM(total_payment) AS total_payment,                                        SUM(total_current_money) AS total_current_money,                                        SUM(total_at) as total_at,                                        SUM(total_pt) as total_pt                             FROM zen_customer_order zco,                                (                                    SELECT zco.customer_order_id,                                            zco.total_order_money,                                            SUM(zcod.product_num) AS total_product,                                            SUM(zcod.product_num*zcod.stamp_price) AS total_at,                                            SUM(zcod.product_num*zcod.store_price) AS total_pt                                    FROM zen_customer_order_detail zcod,zen_customer_order zco ,zen_customer zc,zen_product zp                                    WHERE  zco.customer_order_id=zcod.customer_order_id AND zp.product_id= zcod.product_id                                            AND zco.customer_id=zc.customer_id                                            AND zcod.order_status != 6                                            AND  zco.zen_order_id=$zen_order_id" . $sql_where . "                                    GROUP BY zco.customer_order_id                                ) temp                             WHERE  total_current_money <0                              AND zco.customer_order_id =temp.customer_order_id)";            $result = $this->db->get_results($query_result);            $total_result["total_product"] = 0;//tong so san pham thuc su mua duoc            $total_result["total_customer"] = 0;            $total_result["total_order_money"] = 0;            $total_result["total_payment"] = 0;            $total_result["total_excess_cash"] = 0;            $total_result["total_debit"] = 0;            $total_result["total_at"] = 0;            $total_result["total_pt"] = 0;            if ($result) {                $i = 1;                foreach ($result as $data) {                    if ($i == 1) {                        $total_result["total_customer"] = $data->total_customer;                        $total_result["total_product"] = $data->total_product_real;                        $total_result["total_order_money"] = $data->total_order_money;                        $total_result["total_payment"] = $data->total_payment;                        $total_result["total_excess_cash"] = $data->total_current_money;                        $total_result["total_at"] = $data->total_at;                        $total_result["total_pt"] = $data->total_pt;                        $i++;                    } else {                        $total_result["total_customer"] = $total_result["total_customer"] + $data->total_customer;                        $total_result["total_product"] = $total_result["total_product"] + $data->total_product_real;                        $total_result["total_order_money"] = $total_result["total_order_money"] + $data->total_order_money;                        $total_result["total_payment"] = $total_result["total_payment"] + $data->total_payment;                        $total_result["total_debit"] = $data->total_current_money;                        $total_result["total_at"] = $total_result["total_at"] + $data->total_at;                        $total_result["total_pt"] = $total_result["total_pt"] + $data->total_pt;                        $i++;                    }                }            }            return $customer_order;        }    }    function getListCustomerOrderDetailId($customer_order_id) {        if ($this->db) {            $query = "SELECT  id FROM zen_customer_order_detail zcod                                               WHERE customer_order_id = $customer_order_id                      ";            $customer_order_detail = $this->db->get_results($query);            if ($customer_order_detail) {                $array_id = array();                foreach ($customer_order_detail as $id) {                    $array_id[] = $id->id;                }                return $array_id;            } else {                return false;            }        } else {            return false;        }    }    function syncCustomerOrderMoney($customer_order_id) {        if ($this->db) {            //lấy ra danh sách sản phẩm khách đặt nhưng ko hết hàng            $query = "SELECT  * FROM zen_customer_order_detail zcod WHERE order_status !=6 AND customer_order_id = $customer_order_id";            $list_customer_order_detail = $this->db->get_results($query);            if ($list_customer_order_detail) {                $customer_order_object = $this->getZenCustomerOrderById($customer_order_id);                $total_money = 0;                $total_at = 0;                $total_pt = 0;                foreach($list_customer_order_detail as $item){                    $total_money += intval($item->product_num) * floatval($item->product_price);                    $total_at+= intval($item->product_num) *floatval($item->stamp_price);                    $total_pt+= intval($item->product_num) *floatval($item->store_price);                }                $total_order_money = 0;                $exchange_value = $customer_order_object->exchange;                $percent_service = $customer_order_object->service_percent;                $fee_weight = $customer_order_object->fee_per_kg;                $weight = $customer_order_object->weight;                switch($customer_order_object->type_calculate_payment){                    case 'normal':                        $total_order_money = $total_money;                        break;                    case 'at':                        $total_order_money = $exchange_value*$total_at;                        break;                    case 'pt':                        //tong PT + 5%PT + 12EU*weight                        $total_order_money = $exchange_value*($total_pt + $total_pt*$percent_service/100 + $fee_weight*$weight);                        break;                }                $total_current_money = $customer_order_object->total_payment - $total_order_money;                //update table customer order                $total_order_money = core::roundingMoney($total_order_money);                $total_current_money = core::roundingMoney($total_current_money);                $this->db->query("UPDATE zen_customer_order SET total_order_money=$total_order_money,                        total_store_price = $total_pt,                        total_stamp_price = $total_at,                        total_current_money= $total_current_money                            WHERE customer_order_id=$customer_order_id");                return true;            } else {                //toàn bộ sp trong đơn hàng là hết hàng                $customer_order_object = $this->getZenCustomerOrderById($customer_order_id);                $total_current_money = core::roundingMoney($customer_order_object->total_payment);                $this->db->query("UPDATE zen_customer_order SET total_order_money=0,                        total_store_price = 0,                        total_stamp_price = 0,                        total_current_money= $total_current_money                            WHERE customer_order_id=$customer_order_id");                return true;            }        } else {            return false;        }    }    function getListCustomerOrderFilterToExport($zen_order_id, $order_by, $where, $where_order_status, &$total_result = array()) {        if ($this->db) {            $query = "SELECT  temp.product_id,temp.id,temp.customer_order_id,temp.total_order_money,temp.total_payment,temp.total_current_money,                            zc.customer_id,facebook_name,facebook_link,address,province,phone,                            temp.main_photo,temp.link_web,temp.product_code,temp.product_size,                            temp.product_color,temp.product_num,temp.product_price,                            temp.order_status,temp.customer_order_date                                                                               FROM ( SELECT zcod.product_id,zco.total_order_money,zco.total_payment,zco.total_current_money,zco.customer_id,zcod.id,zcod.customer_order_id,link_web,main_photo,product_code,                                        zcod.product_size,zcod.product_color,product_num,zcod.product_price,                                        order_status,product_available,zcod.customer_order_date                                FROM zen_product zp, zen_customer_order_detail zcod,zen_customer_order zco, zen_order zo                                                                    WHERE zp.product_id = zcod.product_id                                         AND zco.customer_order_id= zcod.customer_order_id                                         AND zco.zen_order_id = zo.zen_order_id AND zo.zen_order_id =$zen_order_id                                ORDER BY zcod.product_id ASC) temp, zen_customer zc                        WHERE zc.customer_id = temp.customer_id ";            if ($where != "") {                $query.=" AND " . $where;            }            if ($where_order_status != "") {                $query.=" AND " . $where_order_status;            }//            if ($order_by != "") {//                $query.=" ORDER BY " . $order_by;//            }            $customer_order = $this->db->get_results($query);            $query_total = "SELECT COUNT(zcod.product_id) AS total_product, zcod.product_id                            FROM zen_customer_order_detail zcod, zen_customer_order zco, zen_order zo                            WHERE  zcod.customer_order_id = zco.customer_order_id AND                                    zco.zen_order_id = zo.zen_order_id                                    AND zo.zen_order_id =$zen_order_id                                                ";            if ($where != "") {                $query_total.=" AND " . $where;            }            if ($where_order_status != "") {                $query_total.=" AND " . $where_order_status;            }            $query_total.=" GROUP BY zcod.product_id";            $data_total = $this->db->get_results($query_total);            if ($data_total) {                foreach ($data_total as $total) {                    $total_result[$total->product_id] = $total->total_product;                }            }            return $customer_order;        }    }    function getReportByOrderId($order_id) {        $query_total = "SELECT SUM(product_num) AS total_product_order, SUM(product_num*zp.product_price) AS total_money_order                                FROM zen_customer_order_detail zcod,zen_customer_order zco,zen_product zp	                                WHERE zcod.customer_order_id= zco.customer_order_id AND zco.zen_order_id=$order_id                                     AND zp.product_id = zcod.product_id";        $total = $this->db->get_row($query_total);        $total_result["total_product_order"] = 0;        $total_result["total_money_order"] = 0;        if ($total) {            $total_result["total_product_order"] = $total->total_product_order;            $total_result["total_money_order"] = $total->total_money_order;        }        $query_result = "(SELECT COUNT(zco.customer_order_id) AS total_customer,SUM(total_order_money) AS total_money_bought,                            SUM(total_payment) AS total_payment,SUM(total_current_money) AS total_current_money,                             temp.total_at, temp.total_pt,temp.total_product_bought                             FROM zen_customer_order zco,(SELECT SUM(zcod.product_num) AS total_product_bought,                                                                SUM(zcod.product_num*zcod.stamp_price) AS total_at,SUM(zcod.product_num*zcod.store_price) AS total_pt                                                            FROM zen_customer_order_detail zcod,zen_customer_order zco                                                            WHERE  zco.customer_order_id=zcod.customer_order_id                                                             AND  zco.zen_order_id=$order_id AND zcod.order_status NOT IN (6,7,8)) temp                             WHERE  total_current_money >=0 AND  zco.zen_order_id=$order_id                            )                             UNION                              (SELECT COUNT(zco.customer_order_id) AS total_customer,SUM(total_order_money) AS total_money_bought,                            SUM(total_payment) AS total_payment,SUM(total_current_money) AS total_current_money,                             temp.total_at, temp.total_pt,temp.total_product_bought                             FROM zen_customer_order zco,(SELECT SUM(zcod.product_num) AS total_product_bought,                                                                SUM(zcod.product_num*zcod.stamp_price) AS total_at,SUM(zcod.product_num*zcod.store_price) AS total_pt                                                            FROM zen_customer_order_detail zcod,zen_customer_order zco                                                            WHERE  zco.customer_order_id=zcod.customer_order_id                                                             AND  zco.zen_order_id=$order_id AND zcod.order_status NOT IN (6,7,8)) temp                             WHERE  total_current_money <0 AND  zco.zen_order_id=$order_id)";        $result = $this->db->get_results($query_result);        $total_result["total_customer"] = 0;        $total_result["total_product_bought"] = 0;        $total_result["total_money_bought"] = 0;        $total_result["total_payment"] = 0;        $total_result["total_excess_cash"] = 0;        $total_result["total_debit"] = 0;        $total_result["total_at_bought"] = 0;        $total_result["total_pt_bought"] = 0;        if ($result) {            $i = 1;            foreach ($result as $data) {                                    if ($i == 1) {                        $total_result["total_customer"] = $data->total_customer;                        $total_result["total_product_bought"] = $data->total_product_bought;                        $total_result["total_money_bought"] = $data->total_money_bought;                        $total_result["total_payment"] = $data->total_payment;                        $total_result["total_excess_cash"] = $data->total_current_money;                        $total_result["total_at_bought"] = $data->total_at;                        $total_result["total_pt_bought"] = $data->total_pt;                        $i++;                    } else {                        $total_result["total_customer"] = $total_result["total_customer"] + $data->total_customer;                        $total_result["total_money_bought"] = $total_result["total_money_bought"] + $data->total_money_bought;                        $total_result["total_payment"] = $total_result["total_payment"] + $data->total_payment;                        $total_result["total_debit"] = $data->total_current_money;                                            }                           }        }                return $total_result;    }//    function getListCustomerOrderByKeyword($zen_order_id, $key, $page = 1, &$load_more = 0, &$total_result = array(), $is_group_customer, $item_per_page = 25) {//        if ($page > 1) {//            $from = ($page - 1) * $item_per_page;//        } else {//            $from = 0;//        }//        if ($this->db) {//            $query = "SELECT  temp.total_product,temp.id,zco.total_order_money,zco.total_payment,zco.total_current_money,temp.customer_order_id,//                            zc.customer_id,facebook_name,facebook_link,address,province,phone,//                            temp.main_photo,temp.link_web,temp.product_code,temp.product_size,//                            temp.product_color,temp.product_num,temp.product_price,//                            temp.order_status,temp.product_available,temp.customer_order_date,//                            temp.online_date,temp.store_date,temp.saled_date,temp.received_date,//                            zco.order_description,temp.description//                        FROM ( SELECT total_product,total_money,zcod.id,zcod.customer_order_id,link_web,main_photo,product_code,//                                        zcod.product_size,zcod.product_color,product_num,zcod.product_price,//                                        order_status,product_available,zcod.customer_order_date,zcod.online_date,//                                        zcod.store_date,zcod.saled_date,zcod.received_date,zcod.description//                                FROM zen_product zp, zen_customer_order_detail zcod,//                                    ( SELECT COUNT(zcod.customer_order_id) AS total_product,SUM(product_num*product_price) AS total_money,zcod.customer_order_id//                                    FROM zen_customer_order_detail zcod, zen_customer_order zco, zen_order zo//                                    WHERE  zcod.customer_order_id = zco.customer_order_id AND//                                    zco.zen_order_id = zo.zen_order_id AND zo.zen_order_id =$zen_order_id//                                GROUP BY zcod.customer_order_id) temp_2//                                WHERE zp.product_id = zcod.product_id //                                        AND temp_2.customer_order_id= zcod.customer_order_id//                                 ORDER BY zcod.id DESC) temp,//                                //                                zen_customer zc, zen_customer_order zco, zen_order zo//                        WHERE temp.customer_order_id = zco.customer_order_id AND //                        zco.zen_order_id = zo.zen_order_id//                        AND zc.customer_id = zco.customer_id AND zo.zen_order_id = $zen_order_id";//            if ($is_group_customer == 0) {//                //search by product code//                $query.=" AND temp.product_code LIKE '%" . $key . "%'";//            } else {//                $query.=" AND facebook_name LIKE '%" . $key . "%'";//            }////            $query.=" LIMIT $from,$item_per_page";//            //var_dump($query);die;//            $customer_order = $this->db->get_results($query);//            $query_total = "SELECT count(id) as total,SUM(product_num) AS total_product//                       FROM zen_customer_order_detail zcod,zen_customer_order zco,zen_customer zc,zen_product zp//                       WHERE zcod.customer_order_id= zco.customer_order_id //                       AND zp.product_id = zcod.product_id//                       AND zc.customer_id = zco.customer_id AND zco.zen_order_id= $zen_order_id//                      ";//            if ($is_group_customer == 0) {//                //search by product code//                $query_total.=" AND product_code LIKE '%" . $key . "%'";//            } else {//                $query_total.=" AND facebook_name LIKE '%" . $key . "%'";//            }////            $total = $this->db->get_row($query_total);//            $total_result["total_product"] = 0;//            if ($total) {//                $total_result["total_product"] = $total->total_product;//                if ($total->total > $page * $item_per_page) {//                    $load_more = 1;//                } else {//                    $load_more = 0;//                }//            } else {//                $load_more = 0;//            }//            $where = '';//            if ($is_group_customer == 0) {//                //search by product code//                $where.=" AND zp.product_code LIKE '%" . $key . "%'";//            } else {//                $where.=" AND facebook_name LIKE '%" . $key . "%'";//            }//            $query_result = "(SELECT COUNT(zco.customer_order_id) AS total_customer, SUM(total_order_money) AS total_order_money,//                SUM(total_payment) AS total_payment, SUM(total_current_money) AS total_current_money// FROM zen_customer_order zco// WHERE  total_current_money >=0//   //  AND customer_order_id IN (SELECT zco.customer_order_id //				FROM zen_customer_order_detail zcod,zen_customer_order zco,zen_customer zc,zen_product zp //				WHERE  zco.customer_order_id=zcod.customer_order_id  AND zp.product_id= zcod.product_id//				AND zco.customer_id=zc.customer_id//				AND  zco.zen_order_id=$zen_order_id" . $where . "  ))// UNION // (SELECT COUNT(zco.customer_order_id) AS total_customer, SUM(total_order_money) AS total_order_money,//                SUM(total_payment) AS total_payment, SUM(total_current_money) AS total_current_money// FROM zen_customer_order zco// WHERE  total_current_money <0//   //  AND customer_order_id IN (SELECT zco.customer_order_id //				FROM zen_customer_order_detail zcod,zen_customer_order zco,zen_customer zc ,zen_product zp //				WHERE  zco.customer_order_id=zcod.customer_order_id  AND zp.product_id= zcod.product_id//				AND zco.customer_id=zc.customer_id//				AND  zco.zen_order_id=$zen_order_id " . $where . " ))";////            $result = $this->db->get_results($query_result);//            $total_result["total_customer"] = 0;//            $total_result["total_order_money"] = 0;//            $total_result["total_payment"] = 0;//            $total_result["total_excess_cash"] = 0;//            $total_result["total_debit"] = 0;//            if ($result) {//////                $i = 1;//                foreach ($result as $data) {//                    if ($data->total_customer > 0) {//                        if ($i == 1) {//                            $total_result["total_customer"] = $data->total_customer;//                            $total_result["total_order_money"] = $data->total_order_money;//                            $total_result["total_payment"] = $data->total_payment;//                            $total_result["total_excess_cash"] = $data->total_current_money;//                            $i++;//                        } else {//                            $total_result["total_customer"] = $total_result["total_customer"] + $data->total_customer;//                            $total_result["total_order_money"] = $total_result["total_order_money"] + $data->total_order_money;//                            $total_result["total_payment"] = $total_result["total_payment"] + $data->total_payment;//                            $total_result["total_debit"] = $data->total_current_money;//                        }//                    }//                }//            }////            return $customer_order;//        }//    }    function checkOrderDetailStatus($customer_order_id) {        if ($this->db) {            $query = "SELECT  id FROM zen_customer_order zco, zen_customer_order_detail zcod                                               WHERE zco.customer_order_id = $customer_order_id                            AND zcod.customer_order_id=zco.customer_order_id                            AND zcod.order_status IN (0,1,2,3,4,5) LIMIT 1                      ";            $customer_order = $this->db->get_row($query);            if ($customer_order) {                return true;            } else {                return false;            }        } else {            return false;        }    }    function checkOrderDetailById($order_detail_id) {        if ($this->db) {            $query = "SELECT  id FROM zen_customer_order_detail zcod WHERE id =" . $order_detail_id;            $customer_order = $this->db->get_row($query);            if ($customer_order) {                return true;            } else {                return false;            }        } else {            return false;        }    }    function checkPaymentOrderDetail($customer_order_id) {        if ($this->db) {            $query = "SELECT  * FROM zen_payment                                            WHERE customer_order_id = $customer_order_id                            LIMIT 1";            $payment_order = $this->db->get_row($query);            if ($payment_order) {                return true;            } else {                return false;            }        } else {            return false;        }    }    function getStatusProductByOrder($zcod_id) {        if ($this->db) {            $query = "SELECT  order_status FROM  zen_customer_order_detail zcod                                               WHERE zcod.id=$zcod_id                      ";            $customer_order = $this->db->get_row($query);            if ($customer_order) {                return $customer_order;            } else {                return false;            }        } else {            return false;        }    }    function deleteOrderDetailById($customer_order_id) {        if ($this->db) {            //remove at table zen_customer_order_detail            $query_delete = "DELETE FROM zen_customer_order_detail                  WHERE customer_order_id=$customer_order_id";            $this->db->query($query_delete);            //remove at table zen_customer_order            $query_delete = "DELETE FROM zen_customer_order                  WHERE customer_order_id=$customer_order_id";            $this->db->query($query_delete);            return true;        } else {            return false;        }    }    function getListCustomer($page = 1, &$load_more = 0, $item_per_page = 25) {        if ($page >= 1) {            $from = ($page - 1) * $item_per_page;        } else {            $from = 0;        }        if ($this->db) {            $query = "SELECT * FROM zen_customer                      ORDER BY customer_id DESC                      LIMIT $from,$item_per_page";            $customer = $this->db->get_results($query);            $query_total = "SELECT count(customer_id) as total                      FROM zen_customer                      ";            $total = $this->db->get_row($query_total);            if ($total) {                if ($total->total > $page * $item_per_page) {                    $load_more = 1;                } else {                    $load_more = 0;                }            } else {                $load_more = 0;            }            return $customer;        } else {            return false;        }    }    function getListExchange(){        if ($this->db) {            $query = "SELECT * FROM zen_exchange ORDER BY created_time DESC                      ";            $list_exchange = $this->db->get_results($query);            return $list_exchange;        } else {            return false;        }    }    function getListCategory() {        if ($this->db) {            $query = "SELECT * FROM zen_category                      ORDER BY category_id";            $category = $this->db->get_results($query);            return $category;        } else {            return false;        }    }    function show_select_category($category_id) {        $array_html = array();        if ($this->db) {            $query = "SELECT category_parent FROM zen_category WHERE category_id=$category_id";            $parent_category = $this->db->get_row($query);            $query_render = "SELECT * FROM zen_category WHERE category_parent=$parent_category->category_parent";            $category_list = $this->db->get_results($query_render);            $temp = '<select class = "category_parent"><option value = "0">Chọn category</option>';            foreach ($category_list as $category) {                if ($category_id == $category->category_id && self::$count_select > 0) {                    $temp.='<option value = "' . $category->category_id . '" selected>' . $category->category_name . ' </option>';                } else {                    $temp.='<option value = "' . $category->category_id . '">' . $category->category_name . ' </option>';                }            }            $temp.='</select>';            $array_html[] = $temp;            if ($parent_category->category_parent > 0) {                self::$count_select++;                $array_html = array_merge($array_html, $this->show_select_category($parent_category->category_parent));            }            return $array_html;        } else {            return false;        }    }    function deleteCategoryById($category_id) {        if ($this->db) {            $query = "SELECT category_id FROM zen_category                      WHERE category_parent=$category_id";            $category = $this->db->get_results($query);            if ($category) {                foreach ($category as $cate_id) {                    $this->deleteCategoryById($cate_id->category_id);                }            }            $query_delete = "DELETE FROM zen_category                  WHERE category_id=$category_id";            $this->db->query($query_delete);            return true;        } else {            return false;        }    }    function getCategoryId($category_id) {        if ($this->db) {            $query = "SELECT * FROM zen_category WHERE category_id =$category_id";            $category = $this->db->get_row($query);            return $category;        } else {            return false;        }    }    function getCategoryByParentId($parent_id) {        if ($this->db) {            $query = "SELECT * FROM zen_category WHERE category_parent =$parent_id AND is_active=1 ORDER BY priority_order";            $category = $this->db->get_results($query);            return $category;        } else {            return false;        }    }    function getTotalChildCategoryById($category_id) {        if ($this->db) {            $query = "SELECT count(category_id) as total FROM zen_category WHERE category_parent =$category_id";            $category = $this->db->get_row($query);            return $category->total;        } else {            return false;        }    }    function getCustomerById($customer_id) {        if ($this->db) {            $query = "SELECT * FROM zen_customer WHERE customer_id =$customer_id";            $customer = $this->db->get_row($query);            return $customer;        } else {            return false;        }    }    function getListProductImage($page, &$load_more, $item_per_page) {        if ($page >= 1) {            $from = ($page - 1) * $item_per_page;        } else {            $from = 0;        }        if ($this->db) {            $query = "SELECT main_photo,product_code FROM zen_product                      ORDER BY product_id DESC                      LIMIT $from,$item_per_page";            $product_image = $this->db->get_results($query);            $query_total = "SELECT count(product_id) as total                      FROM zen_product                      ";            $total = $this->db->get_row($query_total);            if ($total) {                if ($total->total > $page * $item_per_page) {                    $load_more = 1;                } else {                    $load_more = 0;                }            } else {                $load_more = 0;            }            return $product_image;        } else {            return false;        }    }    function getProductById($product_id) {        if ($this->db) {            $query = "SELECT * FROM zen_product WHERE product_id =$product_id";            $product = $this->db->get_row($query);            return $product;        } else {            return false;        }    }    function deleteProductById($product_id) {        if ($this->db) {            $query_delete = "DELETE FROM zen_product                  WHERE product_id=$product_id";            $this->db->query($query_delete);            return true;        } else {            return false;        }    }    function checkOrderHasProduct($product_id) {        if ($this->db) {            $query = "SELECT * FROM zen_customer_order_detail WHERE product_id =$product_id LIMIT 1";            $product = $this->db->get_row($query);            if ($product) {                return true;            } else {                return false;            }        } else {            return false;        }    }    function checkOrderHasCustomer($customer_id) {        if ($this->db) {            $query = "SELECT * FROM zen_customer_order WHERE customer_id =$customer_id LIMIT 1";            $customer = $this->db->get_row($query);            if ($customer) {                return true;            } else {                return false;            }        } else {            return false;        }    }    function deleteCustomerById($customer_id) {        if ($this->db) {            $query_delete = "DELETE FROM zen_customer                  WHERE customer_id=$customer_id";            $this->db->query($query_delete);            return true;        } else {            return false;        }    }    function addOrder($order_name, $order_des) {        if ($this->db) {            $create_time = date('Y-m-d H:i:s');            $query = "INSERT INTO zen_order (zen_order_name,zen_order_description,create_time) VALUES('"                    . $order_name .                    "','" . $order_des . "','".$create_time."')";            $order = $this->db->query($query);            if ($order) {                return $this->db->insert_id;            } else {                return false;            }        } else {            return false;        }    }    function updateOrder($order_id, $order_name, $order_des,$created_time) {        if ($this->db) {            $modified_time = date('Y-m-d H:i:s');            $query = "UPDATE zen_order SET zen_order_name='" . $order_name . "',zen_order_description='" . $order_des . "' , modified_time='".$modified_time."', create_time='".$created_time."' WHERE zen_order_id=" . $order_id;            $order = $this->db->query($query);            if ($order) {                return true;            } else {                return false;            }        } else {            return false;        }    }    function checkZenOrderHasOrderDetail($order_id) {        if ($this->db) {            $query = "SELECT count(customer_order_id) as total from zen_customer_order WHERE zen_order_id=" . $order_id;            $order = $this->db->get_row($query);            if ($order->total > 0) {                return true;            } else {                return false;            }        } else {            return false;        }    }    function deleteOrderById($order_id) {        if ($this->db) {            $query = "DELETE FROM zen_order WHERE zen_order_id=" . $order_id;            $order = $this->db->query($query);            if ($order >= 0) {                return true;            } else {                return false;            }        } else {            return false;        }    }    function getCustomerInfoByPhone($phone) {        if ($this->db) {            $query = "SELECT * FROM zen_customer WHERE phone='" . $phone . "'";            $customer = $this->db->get_row($query);            if ($customer) {                return $customer;            } else {                return false;            }        } else {            return false;        }    }    function getCustomerInfoByFbName($fb_name) {        if ($this->db) {            $query = "SELECT * FROM zen_customer WHERE facebook_name LIKE '%" . $fb_name . "%' LIMIT 10";            $customer = $this->db->get_results($query);            if ($customer) {                return $customer;            } else {                return false;            }        } else {            return false;        }    }    function checkCustomerOrder($customer_id, $zen_order_id) {        if ($this->db) {            $query = "SELECT * FROM zen_customer_order WHERE customer_id =$customer_id AND zen_order_id = $zen_order_id";            $customer_order = $this->db->get_row($query);            if ($customer_order) {                return $customer_order;            } else {                return false;            }        } else {            return false;        }    }    function getProductInfoByCode($product_code) {        if ($this->db) {            $query = "SELECT * FROM zen_product WHERE product_code='" . $product_code . "'";            $product = $this->db->get_row($query);            if ($product) {                return $product;            } else {                return false;            }        } else {            return false;        }    }    function getListPaymentByCustomerOrder($customer_order_id) {        if ($this->db) {            $query = "SELECT * FROM zen_payment WHERE customer_order_id=$customer_order_id";            $payment = $this->db->get_results($query);            if ($payment) {                return $payment;            } else {                return false;            }        } else {            return false;        }    }    function getPaymentById($payment_id) {        if ($this->db) {            $query = "SELECT * FROM zen_payment WHERE id=$payment_id";            $payment = $this->db->get_row($query);            if ($payment) {                return $payment;            } else {                return false;            }        } else {            return false;        }    }    function getOrderById($order_id) {        if ($this->db) {            $query = "SELECT * FROM zen_order WHERE zen_order_id=$order_id";            $order = $this->db->get_row($query);            if ($order) {                return $order;            } else {                return false;            }        } else {            return false;        }    }    function getOtherOrderByCustomerId($customer_id, $customer_order_id) {        if ($this->db) {            $query = "SELECT zen_order_name,total_current_money,customer_order_id                        FROM zen_customer_order,zen_order                        WHERE  zen_order.zen_order_id= zen_customer_order.zen_order_id AND zen_customer_order.customer_id=$customer_id                            AND zen_customer_order.customer_order_id !=" . $customer_order_id . "                        ORDER BY customer_order_id asc";            $order_payment = $this->db->get_results($query);            if ($order_payment) {                return $order_payment;            } else {                return false;            }        } else {            return false;        }    }    function getListFileExportHTML($page = 1, &$load_more = 0, $item_per_page = 25) {        if ($page >= 1) {            $from = ($page - 1) * $item_per_page;        } else {            $from = 0;        }        if ($this->db) {            $query = "SELECT *                                              FROM zen_log_export_html,zen_admin_user                      WHERE user_id = zen_admin_user.id                      ORDER BY created_time DESC                      LIMIT $from,$item_per_page";            $log_file = $this->db->get_results($query);            $query_total = "SELECT count(product_id) as total                      FROM zen_product                      ";            $total = $this->db->get_row($query_total);            if ($total) {                if ($total->total > $page * $item_per_page) {                    $load_more = 1;                } else {                    $load_more = 0;                }            } else {                $load_more = 0;            }            return $log_file;        }    }    function saveLogFileExportHTML($file_name) {        if ($this->db) {            if (empty($_SESSION["username"])) {                return false;            } else {                $user = $this->getUserByName($_SESSION["username"]);                if ($user) {                    $query = "INSERT INTO zen_log_export_html (user_id,filename) VALUES($user->id,'$file_name')";                    $this->db->query($query);                    return true;                } else {                    return false;                }            }        } else {            return false;        }    }    function getUserByName($name) {        if ($this->db) {            $query = "SELECT *                        FROM zen_admin_user                        WHERE  username='$name'                        ";            $user = $this->db->get_row($query);            if ($user) {                return $user;            } else {                return false;            }        } else {            return false;        }    }    function CheckLogin() {        if (!isset($_SESSION)) {            session_start();        }        if (!isset($_SESSION["username"]) || !isset($_SESSION["user_role"])) {            if (isset($_COOKIE['username']) && isset($_COOKIE['password'])) {                $username = $_COOKIE['username'];                $pwdmd5 = $_COOKIE['password'];                $qry = "Select * from zen_admin_user where username='$username' and password='$pwdmd5'";                $result = $this->db->get_row($qry);                if (!$result) {                    return false;                } else {                    $_SESSION["username"] = $username;                    $_SESSION["user_role"] = $result->user_role;                    return true;                }            } else {                return false;            }        }        return true;    }    function Login() {        $username = addslashes(trim($_POST['username']));        $password = addslashes(trim($_POST['password']));        if (!isset($_SESSION)) {            session_start();        }        $pwdmd5 = md5($password);        $qry = "Select * from zen_admin_user where username='$username' and password='$pwdmd5'";        $result = $this->db->get_row($qry);        if (!$result) {            return false;        }        $_SESSION["username"] = $username;        $_SESSION["user_role"] = $result->user_role;        $time = time();        $cookie_time = (3600 * 24 * 30); // 30 days        if (isset($_POST ["remember_user"]) && intval($_POST ["remember_user"]) == 1) {            // Check to see if the 'setcookie' box was ticked to remember the user            setcookie("username", $username, $time + $cookie_time, '/'); // Sets the cookie username            setcookie("password", md5($password), $time + $cookie_time, '/'); // Sets the cookie password            setcookie("remember_user", "yes", $time + $cookie_time * 12, '/'); // Sets the cookie remember user        } else {            $this->removeAllCookiesFromDomain();            setcookie("remember_user", "", $time - 3600, '/'); // Sets the cookie remember user        }        return true;    }    function LogOut() {        session_start();        session_unset();        session_destroy(); //destroy the session        //$_SESSION["username"] = NULL;       // unset($_SESSION["username"]);        $this->removeAllCookiesFromDomain();        return true;    }    function removeAllCookiesFromDomain() {        setcookie("username", '', time() - 3600, '/');        setcookie("password", '', time() - 3600, '/');    }    public function changeDateMysqlToShow($date) {        if ($date != "0000-00-00 00:00:00") {            if ($_SESSION["username"] == 'zen') {                $timezone = 'CET';                $timezone_default = "ICT";                $date_input = new DateTime($date, new DateTimeZone($timezone_default));                $date_input->setTimeZone(new DateTimeZone($timezone));                return $date_input->format('d-m-Y H:i:s');            } else {                $time_int = strtotime($date);                $time_date = date('d-m-Y H:i:s', $time_int);                return $time_date;            }        } else {            return '';        }    }    public function changeDateMysqlToCompare($date) {        if ($date != "0000-00-00 00:00:00") {            if ($_SESSION["username"] == 'zen') {                //convert time Zech ve VN                $timezone = 'ICT';                $timezone_default = "CET";                $date_input = new DateTime($date, new DateTimeZone($timezone_default));                $date_input->setTimeZone(new DateTimeZone($timezone));                return $date_input->format('Y-m-d H:i:s');            } else {                return $date;            }        } else {            return '';        }    }    function vn_str_filter($str) {        $unicode = array(            'a' => 'á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ',            'd' => 'đ',            'e' => 'é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ',            'i' => 'í|ì|ỉ|ĩ|ị',            'o' => 'ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ',            'u' => 'ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự',            'y' => 'ý|ỳ|ỷ|ỹ|ỵ',            'A' => 'Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ',            'D' => 'Đ',            'E' => 'É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ',            'I' => 'Í|Ì|Ỉ|Ĩ|Ị',            'O' => 'Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ỗ|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ',            'U' => 'Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự',            'Y' => 'Ý|Ỳ|Ỷ|Ỹ|Ỵ',        );        foreach ($unicode as $nonUnicode => $uni) {            $str = preg_replace("/($uni)/i", $nonUnicode, $str);        }        return $str;    }    function convert_string_friendly($str) {        $str = strtolower($this->vn_str_filter(trim($str)));        $str = preg_replace('/[^a-z0-9\-\_\s]/', '', $str);        $str = preg_replace('/\s+/', '_', trim($str));        $str = preg_replace('/\_+/', '_', $str);        return $str;    }    function renderPayment($customer_order_id) {        $list_payment = $this->getListPaymentByCustomerOrder($customer_order_id);        $customer_order = $this->getZenCustomerOrderById($customer_order_id);        $customer = $this->getCustomerById($customer_order->customer_id);        //get order name        $order_data = $this->getOrderById($customer_order->zen_order_id);        $order_name = $order_data->zen_order_name;        //get info other order        $other_order = $this->getOtherOrderByCustomerId($customer_order->customer_id, $customer_order_id);        $html = '<table class="table table-striped table-bordered bootstrap-datatable datatable" id="table_customer_order">                        <thead>                            <tr>                                <th>Ngày thanh toán</th>                                <th>Kiểu thanh toán</th>                                <th>Mô tả</th>                                <th>Số tiền<br/>(*1000 VND)</th>                                <th>Actions</th>                            </tr>                        </thead>                           <tbody id="tbody_payment_list">';        if ($list_payment) {            foreach ($list_payment as $payment) {                switch ($payment->type_payment) {                    case 1:                        $type = "Cọc trực tiếp";                        break;                    case 2:                        $type = "Cọc VCB";                        break;                    case 3:                        $type = "Refund VCB";                        break;                    case 4:                        $type = "Refund trực tiếp";                        break;                    case 5:                        $type = "Chuyển tiền";                        break;                }                $html.='<tr>            <td class="center" >' . date('d-m-Y', strtotime($payment->date_payment)) . '</td>            <td class="center">' . $type . '</td>            <td class="center">' . $payment->description . '</td>            <td class="center">' . number_format($payment->payment / 1000) . '</td>            <td class="center" >';                if ($payment->type_payment == 5) {                    $html.='<button  class="btn btn-primary" type="button"                         onClick="action_retransfer_money(this,' . $payment->id . ',' . $payment->other_customer_order_id . ',' . $customer_order_id . ');">Hủy thanh toán</button>';                } else {                    $html.='<a class="btn btn-info btn_edit_payment" href="javascript:void(0)" rel="' . $payment->id . '">                        <i class="icon-edit icon-white"></i>                          Edit                                                                </a>                    <p></p>                    <a href="javascript:void(0)" class="btn btn-danger btn_delete_payment" rel="' . $payment->id . '">                        <i class="icon-trash icon-white"></i>                         Delete                    </a>';                }                $html.='</td>        </tr>';            }            $html.=' <tr><td colspan="3" style="text-align:right">Tổng tiền cọc:</td><td colspan="2">' . number_format($customer_order->total_payment / 1000) . '</td></tr>        </tbody>                    </table>';        }        $html.='<table class="table table-bordered " id="table_calculator_payment">                        <tr><th>Thanh toán</th><th>Đơn vị<br/>(*1000 VND)</th></tr>                        <tr><td>Tổng tiền đơn hàng ' . $order_name . ':</td><td>' . number_format($customer_order->total_order_money / 1000) . '</td></tr>                        <tr><td>Tổng cọc:</td><td>' . number_format($customer_order->total_payment / 1000) . '</td></tr>';        if ($customer_order->total_current_money > 0) {            $html.=' <tr><td><b>' . $order_name . ' còn thừa:</b></td><td>' . number_format($customer_order->total_current_money / 1000) . '</td></tr>';        } elseif ($customer_order->total_current_money < 0) {            $html.='<tr><td><b>' . $order_name . ' còn nợ:</b></td><td>' . number_format($customer_order->total_current_money / 1000) . '</td></tr>';        }        $total_other_money = $customer_order->total_current_money;        if ($other_order) {            foreach ($other_order as $date_order) {                $total_other_money = $total_other_money + $date_order->total_current_money;                if ($date_order->total_current_money > 0) {                    $html.='<tr><td>' . $date_order->zen_order_name . ' còn thừa:                        <button  class="btn btn-primary" type="button"                         onClick="action_transfer_money(this,' . $date_order->customer_order_id . ',' . $customer_order_id . ');">Thanh toán</button>                        </td>                </td>                <td>' . number_format($date_order->total_current_money / 1000) . '</td></tr>';                } elseif ($date_order->total_current_money < 0) {                    $html.='<tr><td>' . $date_order->zen_order_name . ' còn thiếu:                        <button  class="btn btn-primary" type="button"                         onClick="action_transfer_money(this,' . $date_order->customer_order_id . ',' . $customer_order_id . ');">Thanh toán</button>                        </td>                </td>                <td>' . number_format($date_order->total_current_money / 1000) . '</td></tr>';                }            }            if ($total_other_money > 0) {                $html.='<tr><td><b>Tổng tiền của khách ' . $customer->facebook_name . ' :</b></td><td>' . number_format($total_other_money / 1000) . '(còn thừa)</td></tr>';            } elseif($total_other_money < 0) {                $html.='<tr><td><b>Tổng tiền của khách ' . $customer->facebook_name . ' :</b></td><td>' . number_format($total_other_money / 1000) . '(còn nợ)</td></tr>';            }else{                $html.='<tr><td><b>Tổng tiền của khách ' . $customer->facebook_name . ' :</b></td><td>Đã thanh toán đủ</td></tr>';            }        }        $html.='</table>';        return $html;    }    function generateRandomString($length = 10) {        $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';        $randomString = '';        for ($i = 0; $i < $length; $i++) {            $randomString .= $characters[rand(0, strlen($characters) - 1)];        }        return $randomString;    }    public static function roundingMoney($number,$rounding = 1000){        $number = floatval($number);        if($number > 0){            if($number > $rounding){                if($number % $rounding != 0){                    $number = ceil($number / $rounding) * $rounding;                }            }else{                $number = $rounding;            }        }elseif($number < 0){            $rounding = $rounding*(-1);            if($number < $rounding){                if($number % $rounding != 0){                    $number = ceil($number / $rounding) * $rounding;                }            }else{                $number = $rounding;            }        }        return $number;    }}?>